package com.xuanyang.dormrepair.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xuanyang.dormrepair.config.hook.OpenApi;
import com.xuanyang.dormrepair.model.entity.FloorRoom;
import com.xuanyang.dormrepair.model.entity.Notice;
import com.xuanyang.dormrepair.service.NoticeService;
import com.xuanyang.dormrepair.utils.Const;
import com.xuanyang.dormrepair.utils.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @AUTHOR soft
 * @DATE 2019/5/25 18:01
 * @DESCRIBE
 */
@RestController
@RequestMapping("/api")
public class ApiController {

    @Autowired
    private NoticeService noticeService;

    private FloorRoom room;

    @ModelAttribute
    public void init(@RequestAttribute(value = Const.USER, required = false) FloorRoom rm) {
        this.room = rm;
    }

    @OpenApi
    @PostMapping("/notices")
    public RestResponse notices(int page) {
        IPage<Notice> iPage = noticeService.page(page, 10, new Notice());
        if (iPage.getTotal()>0) {
            return RestResponse.ok(iPage);
        }
        return RestResponse.fail();
    }
}
